﻿using System;
using System.Collections.Generic;
using System.Text;

using SB.Logging;
using SB.Database;
using SB.MediaLibrary.Entities;

namespace SB.MediaLibrary
{
    static class InsertTestData
    {
        private static readonly ILogger log = LoggingFacade.GetLogger(typeof(InsertTestData));

        public static void Execute()
        {
            DatabaseFacade.DataAccessInterface.OpenConnection();
            DatabaseFacade.DataAccessInterface.EmptyTables();
            DatabaseFacade.DataAccessInterface.BeginTransaction();

            // Genres
            List<Genre> genres = new List<Genre>();
            genres.Add(new Genre { Name = "Action"});
            genres.Add(new Genre { Name = "Horror" });
            genres.Add(new Genre { Name = "Thriller" });
            genres.Add(new Genre { Name = "Komödie" });
            DatabaseFacade.DataAccessInterface.SaveArray(genres.ToArray());

            // Medien
            List<Medium> medien = new List<Medium>();
            medien.Add(new Medium { Name = "CD" });
            medien.Add(new Medium { Name = "DVD" });
            medien.Add(new Medium { Name = "Blu-Ray" });
            medien.Add(new Medium { Name = "Videofile" });
            DatabaseFacade.DataAccessInterface.SaveArray(medien.ToArray());

            // Filme
            List<Film> filme = new List<Film>();
            int tmp = 0;
            for (int i = 1; i < 10; i++)
            {
                tmp = i / 3;
                filme.Add(new Film { Name = "Film " + i, Genre = genres[tmp], Medium = medien[tmp] });
            }
            DatabaseFacade.DataAccessInterface.SaveArray(filme.ToArray());

            DatabaseFacade.DataAccessInterface.CommitTransaction();
            DatabaseFacade.DataAccessInterface.Flush();
            DatabaseFacade.DataAccessInterface.CloseConnection();
        }
    }
}
